<!--  -->
<script setup>
import { ref } from 'vue'
import { NSkeleton } from 'naive-ui'
import HomeGoods from './home-goods.vue'
import HomePanel from './home-panel.vue'
import More from '../more.vue'
import { findGoods } from '@/api/home';
import { useLazyData } from '@/utils';

const homeProduct = ref(null)
const result = useLazyData(homeProduct, findGoods)

</script>

<template>
  <div class="home-product" ref="homeProduct">
    <Transition>
      <div style="margin: 30px 0px;" v-if="result.length <= 0">
        <n-skeleton height="610px" width="100%" />
      </div>
      <div v-else>
        <HomePanel :title="cate.name" v-for="cate in result" :key="cate.id">
          <template v-slot:right>
            <div class="sub">
              <span v-for="subTitle in cate.children" :key="subTitle.id">
                <RouterLink to="/">{{ subTitle.name }}</RouterLink>
              </span>
            </div>
            <More />
          </template>
          <div class="box">
            <RouterLink class="cover" to="/">
              <img v-lazy="cate.picture" alt />
              <strong class="label">
                <span>{{ cate.name }}馆</span>
                <span v-html="cate.saleInfo"></span>
              </strong>
            </RouterLink>
            <ul class="goods-list">
              <li v-for="goods in cate.goods" :key="goods.id">
                <HomeGoods :goods="goods"></HomeGoods>
              </li>
            </ul>
          </div>
        </HomePanel>
      </div>
    </Transition>
  </div>
</template>

<style scoped lang='less'>
.home-product {
  background: #fff;
  padding: 20px 0px;
  .sub {
    margin-bottom: 2px;
    span {
      &:not(:first-child)::before {
        content: "/";
        font-weight: bold;
      }
      font-size: 15px;
      border-radius: 4px;

      a:hover {
        color: @xtxColor;
      }
      > a {
        margin: 0px 20px;
      }
    }
  }
  .box {
    display: flex;
    .cover {
      width: 240px;
      height: 610px;
      margin-right: 10px;
      position: relative;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
      .label {
        width: 200px;
        height: 50px;
        display: flex;
        font-size: 15px;
        color: #fff;
        line-height: 50px;
        font-weight: normal;
        position: absolute;
        left: 0;
        top: 50%;
        transform: translate3d(0, -50%, 0);
        span {
          text-align: center;
          &:first-child {
            width: 60px;
            background: rgba(0, 0, 0, 0.9);
          }
          &:last-child {
            width: 140px;
            background: rgba(0, 0, 0, 0.7);
          }
        }
      }
    }
    .goods-list {
      width: 990px;
      display: flex;
      flex-wrap: wrap;
      li {
        width: 240px;
        height: 300px;
        margin-right: 10px;
        margin-bottom: 10px;
        &:nth-last-child(-n + 4) {
          margin-bottom: 0;
        }
        &:nth-child(4n) {
          margin-right: 0;
        }
      }
    }
  }
}
</style>